<script setup lang="ts">
import { hostMap } from '@fl/micro/host-map'
import { getJointToken } from '@fl/logics/jointAuth'
import { activatedFn } from '@fl/micro/lifecycle'
import { useRoute } from 'vue-router'
import WujieVue from 'wujie-vue3'
import { useUserStore } from '@fl/store/modules/user'

const userStore = useUserStore()
const orgInfo = userStore.getOrgInfo
const { bus } = WujieVue
const { meta } = useRoute()
const { wujiePath, title } = meta
// console.log('🚀 ~ meta:', meta)

const item = {
    type: title,
    token: getJointToken(),
}

console.log('🚀 ~ hostMapgoodHouse:', hostMap('goodHouse'))

// 删除初始化时的事件发送
// const token = getAccessToken()
// console.log('发送 passAndJump 事件:', token, '/index')
// bus.$emit('passAndJump', token, '/index')

function activatedCallback(appWindow: Window) {
    activatedFn(appWindow)
    console.log('主应用传递企业信息 ', orgInfo)
    console.log('主应用传递token, 并要求子应用跳转到 ', wujiePath)
    console.log('主应用传递数据 passAndJump ', meta, item, wujiePath)
    bus.$emit('passOrginInfo', orgInfo, wujiePath)

    console.log('发送 passAndJump 事件:', item, '/index', 'newGoodHouse')
    bus.$emit('passAndJump', item, '/index', 'newGoodHouse')
}
</script>

<template>
    <!-- 保活模式，name相同则复用一个子应用实例，改变url无效，必须采用通信的方式告知路由变化 :url="hostMap('goodHouse')" -->
    <WujieVue width="100%"
              height="100%"
              name="goodHouse"
              :props="{ data: item }"
              :activated="activatedCallback"
              :url="hostMap('goodHouse')"
    />
</template>
